//
//  TotalFiveScrollView.m
//  OpenYourEyes
//
//  Created by zhanglei on 15/8/11.
//  Copyright (c) 2015年 zhanglei. All rights reserved.
//

#import "TotalFiveScrollView.h"
#import "Header.h"
#import "UIImage+WebP.h"
#import "MoviePlayerViewController.h"

@interface TotalFiveScrollView ()

@property (nonatomic,strong)UIImage *image1;
@property (nonatomic,strong)UIImage *image2;
@property (nonatomic,strong)UIImage *image3;
@property (nonatomic,strong)UIImage *image4;
@property (nonatomic,strong)UIImage *image5;

@end
@implementation TotalFiveScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        _viewScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0 ,0, frame.size.width, frame.size.height)];
        [_viewScroller setPagingEnabled:YES];
        [_viewScroller setShowsHorizontalScrollIndicator:NO];
        _viewScroller.backgroundColor = [UIColor clearColor];
        _viewScroller.userInteractionEnabled = YES;
        [self addSubview:_viewScroller];
        
        
        _scrollView1 = [[BTGlassScrollView alloc] initWithBackgroundImage:_image1];
        _scrollView2 = [[BTGlassScrollView alloc] initWithBackgroundImage:_image2];
        _scrollView3 = [[BTGlassScrollView alloc] initWithBackgroundImage:_image3];
        _scrollView4 = [[BTGlassScrollView alloc] initWithBackgroundImage:_image4];
        _scrollView5 = [[BTGlassScrollView alloc] initWithBackgroundImage:_image5];
        
        [_viewScroller addSubview:_scrollView1];
        [_viewScroller addSubview:_scrollView2];
        [_viewScroller addSubview:_scrollView3];
        [_viewScroller addSubview:_scrollView4];
        [_viewScroller addSubview:_scrollView5];
        
    }
    return self;
}

- (void)setFiveScrollView
{
//    [_viewScroller setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [_viewScroller setContentSize:CGSizeMake(5 * _viewScroller.frame.size.width, 0)];
//    [_viewScroller setContentOffset:CGPointMake( (self.frame.size.width) * _idx , 0) ];

    [_scrollView1 setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2)];
    [_scrollView2 setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2)];
    [_scrollView3 setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2)];
    [_scrollView4 setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2)];
    [_scrollView5 setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2)];
//
    [_scrollView2 setFrame:CGRectOffset(_scrollView2.bounds, _viewScroller.frame.size.width, 0)];
    [_scrollView3 setFrame:CGRectOffset(_scrollView3.bounds, 2 * _viewScroller.frame.size.width, 0)];
    [_scrollView4 setFrame:CGRectOffset(_scrollView4.bounds, 3 * _viewScroller.frame.size.width, 0)];
    [_scrollView5 setFrame:CGRectOffset(_scrollView5.bounds, 4 * _viewScroller.frame.size.width, 0)];
    
}


- (void)setIdx:(NSInteger)idx
{
    _idx = idx;

}

- (void)setSection:(NSArray *)section
{
    _section = section;
    
    DailyModel *model1 = _section[0];
    DailyModel *model2 = _section[1];
    DailyModel *model3 = _section[2];
    DailyModel *model4 = _section[3];
    DailyModel *model5 = _section[4];

    [_scrollView1.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model1.coverForDetail] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        _image1 = image;
    }];
    [_scrollView2.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model2.coverForDetail] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        _image2 = image;
    }];
    [_scrollView3.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model3.coverForDetail] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        _image3 = image;
    }];
    [_scrollView4.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model4.coverForDetail] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        _image4 = image;
    }];
    [_scrollView5.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model5.coverForDetail] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        _image5 = image;
    }];
}


@end
